package com.gcph.zhuoba.main.Fragment;

import com.gcph.zhuoba.R;
import com.gcph.zhuoba.main.activitys.MainActivity;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

public class NearbyGroupFragment extends Fragment {

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View nearbyLayout = inflater.inflate(R.layout.layout_nearby_group,
				container, false);
		//初始化头部按钮
		initBtnEveryone(nearbyLayout);
		initBtnGroup(nearbyLayout);
		initBtnQiufang(nearbyLayout);
		return nearbyLayout;
	}

	/**
	 * 初始化球房按钮点击事件
	 * 
	 * @param nearbyLayout
	 */
	public void initBtnQiufang(View nearbyLayout) {
		Button btnQiufang = (Button) nearbyLayout.findViewById(R.id.btn_qiufang);
		btnQiufang.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 点击球房按钮跳转到球房列表
				FragmentManager fManager = getFragmentManager();
				FragmentTransaction fTransaction = fManager.beginTransaction();
				((MainActivity)getActivity()).hideFragments(fTransaction);
				NearbyFragment nearbyFragment = new NearbyFragment();
				fTransaction.replace(R.id.content, nearbyFragment, "nearbyFragment");

				fTransaction.commit();

			}
		});
	}

	/**
	 * 初始化群按钮点击事件
	 * 
	 * @param nearbyLayout
	 */
	public void initBtnGroup(View nearbyLayout) {
		Button btnGroup = (Button) nearbyLayout.findViewById(R.id.btn_group);
		btnGroup.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 点击群按钮跳转到群列表
				FragmentManager fManager = getFragmentManager();
				FragmentTransaction fTransaction = fManager.beginTransaction();
				((MainActivity)getActivity()).hideFragments(fTransaction);
				NearbyGroupFragment nearbyGroupFragment = new NearbyGroupFragment();
				fTransaction.replace(R.id.content, nearbyGroupFragment, "nearbyGroupFragment");
				fTransaction.commit();
			}
		});
	}

	/**
	 * 初始化所有人按钮点击事件
	 * 
	 * @param nearbyLayout
	 */
	public void initBtnEveryone(View nearbyLayout) {
		Button btnEveryone = (Button) nearbyLayout.findViewById(R.id.btn_everyone);
		btnEveryone.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 点击所有人按钮跳转到所有人列表
				FragmentManager fManager = getFragmentManager();
				FragmentTransaction fTransaction = fManager.beginTransaction();
				((MainActivity)getActivity()).hideFragments(fTransaction);
				NearbyEveryoneFragment nearbyEveryoneFragment = new NearbyEveryoneFragment();
				fTransaction.replace(R.id.content, nearbyEveryoneFragment, "nearbyEveryoneFragment");
				fTransaction.commit();
			}
		});
	}

}
